//
//  GGTWBTableModel.m
//  GGT
//
//  Created by Vision on 14-11-9.
//  Copyright (c) 2014年 GGT. All rights reserved.
//

#import "GGTWBTableModel.h"

@implementation GGTWBTableModel
- (id)initWithDictionary:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.profile_image_url = [[dic objectForKey:@"user"]objectForKey:@"profile_image_url"];
        self.name = [[dic objectForKey:@"user"]objectForKey:@"name"];
        self.created_at = [dic objectForKey:@"created_at"];
        self.created_at = [GGTWBTableModel formatDaySinaTime:self.created_at];
        self.source = [dic objectForKey:@"source"];
        self.source = [self.source stringByReplacingOccurrencesOfString:@"</a>" withString:@""];
        self.source = [self.source substringFromIndex:[self.source rangeOfString:@">"].location+1];
        self.weiboText = [dic objectForKey:@"text"];
        self.pic_urls = [dic objectForKey:@"pic_urls"];
        self.weiboID = [dic objectForKey:@"id"];
        self.retweeted_user = [[[dic objectForKey:@"retweeted_status"]objectForKey:@"user"]objectForKey:@"name"];
        self.retweeted_text = [[dic objectForKey:@"retweeted_status"]objectForKey:@"text"];
        self.retweeted_pic_urls = [[dic objectForKey:@"retweeted_status"] objectForKey:@"pic_urls"];
    }
    return self;
}
+(NSString*)formatDaySinaTime:(NSString*)createAt
{
    //Thu Dec 19 11:57:36 +0800 2013
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"EEE MMM d HH:mm:ss Z yyyy";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
    formatter2.dateFormat = @"yyyy-MM-dd";
    return [formatter2 stringFromDate:[formatter dateFromString:createAt]];
}
- (void)dealloc
{
    [_profile_image_url release];
    [_name release];
    [_created_at release];
    [_source release];
    [_weiboText release];
    [_pic_urls release];
    [_weiboID release];
    [_retweeted_text release];
    [super dealloc];
}
@end
